home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / wexmast / xgetdata.pro < prev   
Text File  |  1997-07-08  |  8KB  |  258 lines

  1. ; $Id: xgetdata.pro,v 1.2 1997/01/15 04:29:15 ali Exp $
  2. ;
  3. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. ;------------------------------------------------------
  7. ;   procedure XGetData_event
  8. ;------------------------------------------------------
  9.  
  10. PRO XGetData_event, event
  11.  
  12. COMMON GF, selection
  13.  
  14. WIDGET_CONTROL, event.id, GET_UVALUE = selected
  15.  
  16. CASE selected OF
  17.   "FILELST": BEGIN
  18.         WIDGET_CONTROL, event.top, SENSITIVE = 0
  19.         WIDGET_CONTROL, event.top, /DESTROY
  20.         selection = event.index + 1
  21.          END
  22.   "CANCEL": WIDGET_CONTROL, event.top, /DESTROY
  23. ENDCASE
  24.  
  25. END
  26. ;---------- end of procedure XGetData_event ------------
  27.  
  28.  
  29.  
  30. ;------------------------------------------------------
  31. ;   procedure XGetData
  32. ;------------------------------------------------------
  33.  
  34. PRO XGetData,     NEWDATA, GROUP = GROUP, $
  35.         DESCRIPTION = DESCRIPTION, $
  36.         DIMENSIONS = DIMENSIONS, $
  37.         ONE_DIM = ONE_DIM, $
  38.         TWO_DIM = TWO_DIM, $
  39.         THREE_DIM = THREE_DIM, $
  40.         TITLE = TITLE, $
  41.         FILENAME = FILENAME, $
  42.         OFILENAME = OFILENAME, $
  43.         ASSOC_IT = ASSOC_IT
  44.  
  45. ;+
  46. ; NAME:
  47. ;    XGetData
  48. ; PURPOSE:
  49. ;    Retrieves a data file from the images directory in the main IDL
  50. ;    directory.  The file can be specified when calling the routine
  51. ;    or the file can be chosen by the user with a widget that lets them
  52. ;    make the selection.
  53. ; CATEGORY:
  54. ;    Widgets
  55. ; CALLING SEQUENCE:
  56. ;    XGetData, NEWDATA
  57. ; KEYWORD PARAMETERS:
  58. ;    ASSOC_IT = When set, this keyword forces the routine to return
  59. ;        an associated variable instead of a standard IDL variable.  
  60. ;        This is more efficient when loading animations for instance
  61. ;        as it removes the need to create two copies of the data
  62. ;        in memory (one for the animation, one for the load data).
  63. ;    DESCRIPTION = This keyword returns the description of the data
  64. ;        selected by the XGetData routine (NEWDATA).
  65. ;    DIMENSIONS = This keyword returns the dimensions of the data
  66. ;        selected by the XGetData routine.  These dimensions 
  67. ;        are the dimensions of the NEWDATA variable.
  68. ;    FILENAME = The name of the file that is to be selected from the
  69. ;        images subdirectory.  If this keyword is set, no user 
  70. ;        selection widget is created.
  71. ;    OFILENAME = name of file selected.
  72. ;    ONE_DIM = This keyword is set when the routine is to consider
  73. ;        one dimensional data from the data contained in the
  74. ;        images subdirectory.
  75. ;    TWO_DIM = This keyword is set when the routine is to consider
  76. ;        two dimensional data from the data contained in the
  77. ;        images subdirectory.  When searching for two dimensional
  78. ;        data, this routine will use the first slice of any 
  79. ;        three dimensional data that it encounters.
  80. ;    THREE_DIM = This keyword is set when the routine is to consider
  81. ;        three dimensional data from the data contained in the
  82. ;        images subdirectory.
  83. ;    TITLE = The string that will appear in the title portion
  84. ;        of the data selection widget.  If not specified, the
  85. ;        title will be "Please Select Data".
  86. ; OUTPUTS:
  87. ;    NEWDATA = the variable that is to be filled with the new data.
  88. ; COMMON BLOCKS:
  89. ;    GF - maintains which selection was made when using the data
  90. ;        selection widget.
  91. ; SIDE EFFECTS:
  92. ;    Desensitizes all the other widgets and is modal in behavior.  It 
  93. ;    forces the user to make a selection before proceeding with other 
  94. ;    widget functions.
  95. ; RESTRICTIONS:
  96. ;    Needs to have directory called images in the main IDL directory
  97. ;    (IDL_DIR) and the directory must contain a file called data.txt
  98. ;    that describes the contents of the directory.
  99. ; PROCEDURE:
  100. ;    If the FILENAME keyword was not set, determine the file name using
  101. ;    a widget that lets the user make a selection from the data.txt file
  102. ;    and then open that file, read the data, dimensions, and description,
  103. ;    and return the data.
  104. ; MODIFICATION HISTORY:
  105. ;    Written by Steve Richards,    Dec, 1990
  106. ;-
  107.  
  108.  
  109. COMMON GF, selection
  110.  
  111. datapath = FILEPATH("", SUBDIR = ['examples', 'data'] )
  112.  
  113. name = ''
  114. dim = lonarr(3)
  115. des = ''
  116. del = ''
  117. numfiles = 0L
  118. ONE_MASK = 1
  119. TWO_MASK = 2
  120. THREE_MASK = 4
  121.  
  122. NEWDATA = 0
  123. DESCRIPTION = 0
  124. DIMENSIONS = 0
  125.  
  126. IF (KEYWORD_SET(FILENAME)) THEN BEGIN
  127.   OPENR, unit, datapath + "data.txt", /GET_LUN
  128.   READF, unit, numfiles
  129.   IF (numfiles NE 0) THEN BEGIN
  130.     goodindex = 0
  131.     nameindex = 0
  132.     WHILE((nameindex LT (numfiles)) AND (goodindex EQ 0)) DO BEGIN
  133.       READF, unit, name, dim, des, del
  134.       IF (name EQ FILENAME) THEN goodindex = 1
  135.       IF (del NE '*') THEN MESSAGE, "* delimiter not found in data.txt"
  136.     ENDWHILE
  137.     FREE_LUN, unit
  138.     IF (goodindex NE 0) THEN BEGIN
  139.     ofilename = filename
  140.       OPENR, unit, datapath + FILENAME, /GET_LUN, /BLOCK
  141.       if KEYWORD_SET(ASSOC_IT) then begin
  142.     NEWDATA = ASSOC(unit, bytarr(dim[0],dim[1]))
  143.       ENDIF ELSE BEGIN
  144.     NEWDATA = bytarr(dim[0], dim[1], dim[2])
  145.     READU, unit, NEWDATA
  146.     FREE_LUN, unit
  147.       ENDELSE
  148.       DESCRIPTION = des
  149.       DIMENSIONS = dim
  150.     ENDIF
  151.   ENDIF
  152. ENDIF ELSE IF ((XRegistered("XGetData") EQ 0)) THEN BEGIN
  153.  
  154.   FILTER = 0
  155.   IF KEYWORD_SET(ONE_DIM) THEN FILTER = FILTER OR ONE_MASK
  156.   IF KEYWORD_SET(TWO_DIM) THEN FILTER = FILTER OR TWO_MASK OR THREE_MASK
  157.   IF KEYWORD_SET(THREE_DIM) THEN FILTER = FILTER OR THREE_MASK
  158.   IF (FILTER EQ 0) THEN FILTER = ONE_MASK + TWO_MASK + THREE_MASK
  159.  
  160.   OPENR, unit, datapath + "data.txt", /GET_LUN
  161.   READF, unit, numfiles
  162.   IF (numfiles NE 0) THEN BEGIN
  163.     names = STRARR(numfiles)
  164.     descriptions = STRARR(numfiles)
  165.     dimensions = LONARR(3,numfiles)
  166.     goodindex = 0
  167.     FOR nameindex = 0, numfiles - 1 DO BEGIN
  168.       READF, unit, name, dim, des, del
  169.       TEMPFILT = 0
  170.       IF DIM[0] GT 1 THEN TEMPFILT = ONE_MASK
  171.       IF DIM[1] GT 1 THEN TEMPFILT = TWO_MASK
  172.       IF DIM[2] GT 1 THEN TEMPFILT = THREE_MASK
  173.       IF ((TEMPFILT AND FILTER) NE 0) THEN BEGIN
  174.         names[goodindex] = name
  175.         dimensions[*,goodindex] = dim
  176.         descriptions[goodindex] = des
  177.         goodindex = goodindex + 1
  178.       ENDIF
  179.       IF (del NE '*') THEN MESSAGE, "* delimiter not found in data.txt"
  180.     ENDFOR
  181.     FREE_LUN, unit
  182.  
  183.     neworder = SORT(names[0:goodindex-1])
  184.     names = names[neworder]
  185.     descriptions = descriptions[neworder]
  186.     dimensions = dimensions[*,neworder]
  187.  
  188.     filler = "........................................"
  189.     fullnames = STRARR(goodindex)
  190.     FOR i = 0, goodindex - 1 DO BEGIN
  191.       dimstring = STRING(dimensions[*,i], $
  192.             FORMAT = '("[",I0.3,", ",I0.3,", ",I0.3,"]")')
  193.       length = STRLEN(names[i])
  194.       lengthdim = STRLEN(dimstring)
  195.       fullnames[i] = names[i] + $
  196.         STRMID(filler, 0, 30-length) + $
  197.         dimstring + $
  198.         STRMID(filler, 0, 30-lengthdim) + $
  199.         descriptions[i]
  200.     ENDFOR
  201.  
  202.     IF (NOT(KEYWORD_SET(TITLE))) THEN TITLE =  "Please Select Data"
  203.  
  204. ;    font = '*fixed*'   ;It seems to be impossible to find
  205. ;        a simple font on all servers.
  206.     loadbase = WIDGET_BASE(TITLE = TITLE, $
  207.         GROUP_LEADER = GROUP, /MODAL, /COLUMN, $
  208.         XPAD = 50, $
  209.         YPAD = 50, $
  210.         SPACE = 20)
  211.  
  212.     loadbox = WIDGET_BASE(loadbase, $
  213.         /COLUMN, $
  214.         /FRAME, $
  215.         SPACE = 10)
  216.  
  217. ;    loadlbl = WIDGET_LABEL(loadbox, $
  218. ;        VALUE = "File Name                     Dimensions                    Description")
  219.  
  220.     loadlist = WIDGET_LIST(loadbox, $
  221.         VALUE = fullnames, $
  222.         UVALUE = "FILELST", $
  223.         YSIZE = 10)
  224.  
  225.     loadcancel = WIDGET_BUTTON(loadbase, VALUE = "Cancel", UVALUE = "CANCEL")
  226.  
  227.     WIDGET_CONTROL, loadbase, /REALIZE
  228.   
  229.     selection = 0
  230.  
  231.     Xmanager, "XGetData", loadbase
  232.     IF (selection NE 0) THEN BEGIN
  233.       IF ((NOT(KEYWORD_SET(THREE_DIM))) AND $
  234.      (dimensions[2,selection-1] NE 1)) THEN $
  235.     dimensions[2,selection-1] = 1
  236.       OPENR, unit, datapath + names[selection - 1], /GET_LUN, /BLOCK
  237.       ofilename = names[selection - 1]
  238.       IF KEYWORD_SET(ASSOC_IT) THEN BEGIN
  239.     NEWDATA = ASSOC(unit, bytarr(dimensions[0, selection-1], $
  240.             dimensions[1, selection-1]))
  241.       ENDIF ELSE BEGIN
  242.           NEWDATA = BYTARR(dimensions[0, selection - 1], $
  243.                    dimensions[1, selection - 1], $
  244.                    dimensions[2, selection - 1])
  245.           READU, unit, NEWDATA
  246.           FREE_LUN, unit
  247.       ENDELSE
  248.       DESCRIPTION = descriptions[selection - 1]
  249.       DIMENSIONS = dimensions[*,selection - 1]
  250.     ENDIF
  251.   ENDIF
  252. ENDIF
  253.  
  254. END
  255. ;------------- end of procedure XGetData --------------
  256.  
  257.  
  258.